﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace InformationExtraction.Common
{
    class ClassifyReport
    {
        public ClassifyReport()
        {
            Precision = new float[4];
            Recall = new float[4];
        }

        public InformationType Attribute
        {
            get;
            set;
        }

        public float[] Precision
        {
            get;
            set;
        }

        public float[] Recall
        {
            get;
            set;
        }

        public float[] FMeasure
        {
            get
            {
                float[] fs = new float[Precision.Length];

                for (int i = 0; i < Precision.Length; i++)
                    fs[i] = 2.0f * (Precision[i] * Recall[i]) / (Precision[i] + Recall[i]);

                return fs;
            }
        }

        public float AveragePrecision
        {
            get
            {
                float ave = 0;
                for (int i = 0; i < Precision.Length; i++)
                {
                    ave += Precision[i];
                }
                
                return ave / Precision.Length;
            }
        }

        public float AverageRecall
        {
            get
            {
                float ave = 0;
                for (int i = 0; i < Recall.Length; i++)
                {
                    ave += Recall[i];
                }

                return ave / Recall.Length;
            }
        }

        public float AverageFMeasure
        {
            get
            {
                float ave = 0;
                for (int i = 0; i < FMeasure.Length; i++)
                {
                    ave += FMeasure[i];
                }

                return ave / FMeasure.Length;
            }
        }


        public override string ToString()
        {
            string output = "******************** " + Attribute + " ********************\r\n";
            for (int i = 0; i < Precision.Length; i++)
            {
                output += "Test Set " + (i + 1).ToString() + ":";
                output += "            Precision: " + Precision[i] * 100 + "%\n";
                output += "            Recall: " + Recall[i] * 100 + "%\n";
                output += "            F-Measure: " + FMeasure[i] * 100 + "%\r\n";
            }
            output += "--------------------------------------------------\r\n";
            output += "Average Precision: " + AveragePrecision * 100 + "%\n";
            output += "Average Recall: " + AverageRecall * 100 + "%\n";
            output += "Average F-Measure: " + AverageFMeasure * 100 + "%\r\n";
            output += "**************************************************\r\n";
            return output;
        }
    }
}
